//
//  ViewController.swift
//  Wuhanjiayou
//
//  Created by mac on 2022/3/18.
//

import UIKit

class ViewController: UIViewController {
    var str: String = ""
    
    @IBOutlet weak var wu: UIButton!
    @IBOutlet weak var han: UIButton!
    @IBOutlet weak var jia: UIButton!
    @IBOutlet weak var you: UIButton!
    
    
    @IBOutlet weak var yu: UIButton!
    @IBOutlet weak var shu: UIButton!
    @IBOutlet weak var lin: UIButton!
    @IBOutlet weak var feng: UIButton!
    
    @IBOutlet weak var yi: UIButton!
    @IBOutlet weak var biao: UIButton!
    @IBOutlet weak var ren: UIButton!
    @IBOutlet weak var cai: UIButton!
    
    @IBOutlet weak var chen: UIButton!
    @IBOutlet weak var yu1: UIButton!
    @IBOutlet weak var luo: UIButton!
    @IBOutlet weak var yan: UIButton!
    
    @IBOutlet weak var displayOfVictory: UILabel!
    @IBOutlet weak var displayOfNationalFlag: UILabel!
    
    @IBOutlet weak var victory: UILabel!
    @IBOutlet weak var yibiaorencai: UILabel!
    @IBOutlet weak var chenyuluoyan: UILabel!
    @IBOutlet weak var yushulinfeng: UILabel!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        yibiaorencai.isHidden=true
        yushulinfeng.isHidden=true
        chenyuluoyan.isHidden=true                      
        displayOfVictory.isHidden = true
        displayOfNationalFlag.isHidden = true
        victory.isHidden=true
    }
   
    @IBAction func pressWuhan(_ sender: UIButton) {
        if let text=sender.currentTitle {
            pressWuhanCharacter(with: text)
            
        }
    }
    
    
    @IBAction func XiPai(_ sender: UIButton) {
        let random = arc4random_uniform(4) + 1
        if(random==1){
            wu.setTitle("汉", for: .normal)
            han.setTitle("武", for: .normal)
            jia.setTitle("油", for: .normal)
            you.setTitle("加", for: .normal)
            
            yu.setTitle("风", for: .normal)
            shu.setTitle("临", for: .normal)
            lin.setTitle("树", for: .normal)
            feng.setTitle("玉", for: .normal)
            
            yi.setTitle("表", for: .normal)
            biao.setTitle("人", for: .normal)
            ren.setTitle("一", for: .normal)
            cai.setTitle("才", for: .normal)
            
            chen.setTitle("落", for: .normal)
            yu1.setTitle("沉", for: .normal)
            luo.setTitle("鱼", for: .normal)
            yan.setTitle("雁", for: .normal)
            
        }
        if(random==2){
            wu.setTitle("油", for: .normal)
            han.setTitle("加", for: .normal)
            jia.setTitle("武", for: .normal)
            you.setTitle("汉", for: .normal)
            
            yu.setTitle("临", for: .normal)
            shu.setTitle("风", for: .normal)
            lin.setTitle("玉", for: .normal)
            feng.setTitle("树", for: .normal)
            
            yi.setTitle("一", for: .normal)
            biao.setTitle("人", for: .normal)
            ren.setTitle("表", for: .normal)
            cai.setTitle("才", for: .normal)
            
            chen.setTitle("鱼", for: .normal)
            yu1.setTitle("雁", for: .normal)
            luo.setTitle("沉", for: .normal)
            yan.setTitle("落", for: .normal)
        }
        if(random==3){
            wu.setTitle("加", for: .normal)
            han.setTitle("武", for: .normal)
            jia.setTitle("汉", for: .normal)
            you.setTitle("油", for: .normal)
            
            yu.setTitle("临", for: .normal)
            shu.setTitle("树", for: .normal)
            lin.setTitle("风", for: .normal)
            feng.setTitle("玉", for: .normal)
            
            yi.setTitle("才", for: .normal)
            biao.setTitle("表", for: .normal)
            ren.setTitle("一", for: .normal)
            cai.setTitle("人", for: .normal)
            
            chen.setTitle("落", for: .normal)
            yu1.setTitle("鱼", for: .normal)
            luo.setTitle("沉", for: .normal)
            yan.setTitle("雁", for: .normal)
        }
        if(random==4){
            wu.setTitle("武", for: .normal)
            han.setTitle("加", for: .normal)
            jia.setTitle("油", for: .normal)
            you.setTitle("汉", for: .normal)
            
            yu.setTitle("树", for: .normal)
            shu.setTitle("临", for: .normal)
            lin.setTitle("玉", for: .normal)
            feng.setTitle("风", for: .normal)
            
            yi.setTitle("人", for: .normal)
            biao.setTitle("才", for: .normal)
            ren.setTitle("一", for: .normal)
            cai.setTitle("表", for: .normal)
            
            chen.setTitle("雁", for: .normal)
            yu1.setTitle("沉", for: .normal)
            luo.setTitle("鱼", for: .normal)
            yan.setTitle("落", for: .normal)
        }
        yu.isEnabled=true
        shu.isEnabled=true
        lin.isEnabled=true
        feng.isEnabled=true
        
        wu.isEnabled=true
        han.isEnabled=true
        jia.isEnabled=true
        you.isEnabled=true
        
        yi.isEnabled=true
        biao.isEnabled=true
        ren.isEnabled=true
        cai.isEnabled=true
        
        chen.isEnabled=true
        yu1.isEnabled=true
        luo.isEnabled=true
        yan.isEnabled=true
        yibiaorencai.isHidden=true
        yushulinfeng.isHidden=true
        chenyuluoyan.isHidden=true
        displayOfVictory.isHidden = true
        displayOfNationalFlag.isHidden = true
        victory.isHidden=true
        
    }
    func pressWuhanCharacter(with wuhanCharacter:String){
        str.append(wuhanCharacter)
        if str.count>=4{
            let suffixSubStr = str.suffix(4)
            
            if suffixSubStr == "武汉加油"{
                wu.isEnabled=false
                han.isEnabled=false
                jia.isEnabled=false
                you.isEnabled=false
                displayOfVictory.isHidden = false
                displayOfNationalFlag.isHidden = false
                
            }
            if suffixSubStr == "玉树临风"{
                yu.isEnabled=false
                shu.isEnabled=false
                lin.isEnabled=false
                feng.isEnabled=false
                yushulinfeng.isHidden=false
              
            }
            if suffixSubStr == "一表人才"{
                yi.isEnabled=false
                biao.isEnabled=false
                ren.isEnabled=false
                cai.isEnabled=false
                yibiaorencai.isHidden=false
               
            }
            if suffixSubStr == "沉鱼落雁"{
                chen.isEnabled=false
                yu1.isEnabled=false
                luo.isEnabled=false
                yan.isEnabled=false
                chenyuluoyan.isHidden=false
              
            }
            if yibiaorencai.isHidden==false
              ,yushulinfeng.isHidden==false
              ,chenyuluoyan.isHidden==false
              ,displayOfVictory.isHidden == false
              , displayOfNationalFlag.isHidden==false {
                victory.isHidden=false
                
            }
            
        }
        
    }
    
}

